package com.deer.wms.ASN.manage.web;

import com.deer.wms.ASN.manage.model.file.RequestBuyDetailFile;
import com.deer.wms.ASN.manage.model.file.RequestBuyDetailFileCriteria;
import com.deer.wms.ASN.manage.model.file.RequestBuyDetailFileDto;
import com.deer.wms.ASN.manage.service.RequestBuyDetailFileService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.deer.wms.project.root.core.result.Result;
import com.deer.wms.project.root.core.result.ResultGenerator;

import java.util.List;

/**
* Created by guo on 2020/01/05.
*/
@Api(description = "归档采购详情api接口")
@RestController
@RequestMapping("/request/buy/detail/files")
public class RequestBuyDetailFileController {

    @Autowired
    private RequestBuyDetailFileService requestBuyDetailFileService;

    @PostMapping("/insert")
    public Result add(@RequestBody RequestBuyDetailFile requestBuyDetailFile) {
        requestBuyDetailFileService.save(requestBuyDetailFile);
        return ResultGenerator.genSuccessResult();
    }

    @GetMapping("/delete")
    public Result delete(Integer id) {
        requestBuyDetailFileService.removeById(id);
        return ResultGenerator.genSuccessResult();
    }

    @PostMapping("/update")
    public Result update(@RequestBody RequestBuyDetailFile requestBuyDetailFile) {
        requestBuyDetailFileService.updateById(requestBuyDetailFile);
        return ResultGenerator.genSuccessResult();
    }

    @GetMapping("/detail")
    public Result detail(@PathVariable Integer id) {
        RequestBuyDetailFile requestBuyDetailFile = requestBuyDetailFileService.getById(id);
        return ResultGenerator.genSuccessResult(requestBuyDetailFile);
    }

    @GetMapping("/list")
    public Result list(RequestBuyDetailFileCriteria criteria) {
        PageHelper.startPage(criteria.getPageNum(), criteria.getPageSize());
        List<RequestBuyDetailFileDto> list = requestBuyDetailFileService.findList(criteria);
        PageInfo pageInfo = new PageInfo(list);
        return ResultGenerator.genSuccessResult(pageInfo);
    }

}
